﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using MVVM_CAD.Common;
using MVVM_CAD.Model;
using System.Windows.Controls;

namespace MVVM_CAD.Strategy
{
    public class SelectionToolStrategy : StrategyBase
    {
        public SelectionToolStrategy(IFigure figure)
            : base(figure)
        {
        }

        public override IFigure PerformMouseLeftClicUpEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseMoveEvent(IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseMoveEvent(DrawingCanvas Canvas, CustomPoint point)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            if (Figure.PointsCollection.Count != 0) FigureDrawer.DrawFigure(canvas, Figure);
            foreach (var figure in figures)
                try
                {
                    if (figure.PointsCollection.Single(p => p.X == point.X && p.Y == point.Y) != null)
                        Figure = figure;
                }
                catch (InvalidOperationException)
                {}

            if (Figure.DrawStatus == DrawStatus.Completed)
            {
                Figure.PointsCollection.ForEach(p => p.Color = Colors.Red);
                FigureDrawer.DrawFigure(canvas, Figure);
            }

            return Figure;
        }
    }
}
